fix missing json output for theme info command when dev and theme flags are missing#6905
fix missing json output for theme info command when dev and theme flags are missing#6905
Conversation
|
🤖 Code Review · #projects-dev-ai for questions ✅ Complete - No issues 📋 History✅ 1 findings → ✅ No issues |
070e0fa to
d198b78
Compare
|
These findings are in files not modified by this PR and cannot be posted as inline comments.
|
| json?: boolean | ||
| } | ||
|
|
||
| interface DevInfo { |
There was a problem hiding this comment.
Could we rename this to ThemeEnvironmentInfo?
There was a problem hiding this comment.
absolutely. I chose devInfo bc there was an existing function that gathers the same/ similar info called
export async function fetchDevInfo(config: {cliVersion: string}): Promise<AlertCustomSection[]> {
return [devConfigSection(), await systemInfoSection(config)]
}
function devConfigSection(): AlertCustomSection {
const store = getThemeStore() ?? 'Not configured'
const developmentTheme = getDevelopmentTheme()
recordEvent(`theme-command:info:dev-theme-loaded:${developmentTheme}`)
return tabularSection('Theme Configuration', [
['Store', store],
['Development Theme ID', developmentTheme ? `#${developmentTheme}` : {subdued: 'Not set'}],
])
}
But I agree, ThemeEnvironmentInfo is more descriptive
There was a problem hiding this comment.
and since I'm changing the Interface name I'm going to change the function that returns this type to match as well, to: themeEnvironmentInfoJSON
| const store = getThemeStore() | ||
| return { | ||
| store: store ?? 'Not configured', | ||
| development_theme_id: store ? getDevelopmentTheme() ?? null : null, |
There was a problem hiding this comment.
This took me a minute to understand. If you don't want to make it more verbose can we wrap the first part in () so like development_theme_id: store ? (getDevelopmentTheme() ?? null) : null, ? That way you can more easily ready that it's getDevelopmentTheme that may return null OR that if store isn't found we don't want to run that method and skip right to null as well.
There was a problem hiding this comment.
the linter unfortunately strips the ( ) as unnecessary. I will use a multi line conditional, I also agree it is difficult to read
| renderInfo(formattedInfo) | ||
| } else { | ||
| const infoMessage = await fetchDevInfo({cliVersion: this.config.version}) | ||
| if (flags.json) { |
There was a problem hiding this comment.
It looks like we're calling flags.json twice now. Can you look into merging that logic?
There was a problem hiding this comment.
What did you have in mind? I'm not sure I'm following.
The branching is:
if dev or theme flag present, proceed to json flag check, if present, return one converted result
OR if dev and theme flags are not present, proceed to json flag check, if present, return a *different converted result
because the initial check for theme and dev flags means there will be different data to jsonify based on that check, I don't think I can combine the json checks at a higher level further up the chain (if that's what you meant)
There was a problem hiding this comment.
Ah yes that makes sense. It does do two different things so we can't really unify it.
On another note, can you move the new if (flags.json) one level up above const infoMessage = await fetchDevInfo({cliVersion: this.config.version})?
Right now what happens is that line gets run if we hit the else branch, and then if json is enabled we do nothing with that code. We should check if it's going to be json first and if not, run the const infoMessage...
WHY are these changes introduced?
Fixes #1064 : Theme info not outputting json with the --json flag
I identified that when running
shopify theme info --jsonwithout a--themeor--developmentflag, execution goes to the else branch, which had no JSON handling. TheJSON.stringifylogic only existed in theifbranch (which requires--themeor--development)The
elsebranch had no--jsonhandling at all, so the flag was silently ignored.WHAT is this pull request doing?
I could have chosen to jsonify the existing info message, but this was formulated for the tabular data to output the formatted box in the terminal and looks messy and is more difficult to parse. It would have looked like this:
Click to expand
Output:
I chose to make a new, more easily parse-able json object (following the pattern of the if branch, where a clean object is also created specifically to be consumed by
JSON.stringify). I built a new Interface and function to populate the object inpackages/theme/src/cli/services/info.ts, then consumed it in theelsebranch inpackages/theme/src/cli/commands/theme/info.tsI wrote a new unittest to verify that the JSON conversion is working correctly.
All existing tests pass.
How to test your changes?
while on main, run
shopify theme info --json, should see no json and formulated tabular info like this:then pull down my branch locally,

p build,run
shopify-dev theme info --jsonsee the nice JSON formatting!
Measuring impact
How do we know this change was effective? Please choose one: